﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MessageWorkflow.Dispatch
{
    /// <summary>
    /// Dispatches each ex to the channel specified
    /// </summary>
    public class DispatchErrorStrategy : IErrorStrategy
    {
        private WorkflowChannel _channel;

        public DispatchErrorStrategy(WorkflowChannel channel)
        {
            if (channel == null)
                throw new ArgumentNullException("channel");

            _channel = channel;
        }

        public bool OnError(Exception ex)
        {
            DispatchErrorMessage errorMessage = new DispatchErrorMessage(ex);

            _channel.BeginDispatch(null, errorMessage, this);

            return true;
        }

        public void OnComplete()
        {
            // nothing to handle here since we already dispatched each ex away      
        }
    }
}
